package com.laivi.basic.model.file.reader;

import java.io.File;
import java.io.IOException;

import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

public class XlsReader implements IExcelReader{
	private Workbook book;
	private Sheet sheet;
	
	public XlsReader(String path){
		this(new File(path));
	}
	
	public XlsReader(File file){
		try {
			book= Workbook.getWorkbook(file);
		} catch (BiffException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	@Override
	public void setSheet(int index) {
		sheet=book.getSheet(index);
	}

	@Override
	public String getContent(int row, int col) {
		return sheet.getCell(col, row).getContents();
	}

	@Override
	public void close() {
		if(book!=null){
			book.close();
		}
	}

	@Override
	public int getRowNum() {
		return sheet.getRows();
	}

}
